import pandas as pd
import pyecharts.options as opts
import time
from pyecharts.charts import Line
class Bookline:
    def __init__(self):
        # 1：数据采集
        #书籍名称	借阅人姓名	班级	借阅日期	借阅天数
        bookrecords = pd.read_csv("data/书籍借阅记录.csv", encoding='utf-8-sig')
        print(type(bookrecords['书籍名称']))
        monlist =[time.strptime(date,'%Y/%m/%d').tm_mon for date  in  list(bookrecords['借阅日期'])]
        bookcount = bookrecords['书籍名称'].groupby(monlist).count()
        print(bookcount)

        # 3:数据可视化
        x_data = [ str(key)+'月' for key in list(bookcount.keys())]
        y_data = list(bookcount)
        (
            Line(init_opts=opts.InitOpts(width="100%", height="100%", bg_color="#e9e2e200"))
                .set_global_opts(
                tooltip_opts=opts.TooltipOpts(is_show=True),
                xaxis_opts=opts.AxisOpts(type_="category"),
                yaxis_opts=opts.AxisOpts(
                    type_="value",
                    axistick_opts=opts.AxisTickOpts(is_show=True),
                    splitline_opts=opts.SplitLineOpts(is_show=True),
                ),
            )
                .add_xaxis(xaxis_data=x_data)
                .add_yaxis(
                series_name="",
                y_axis=y_data,
                symbol="emptyCircle",
                is_symbol_show=True,
                label_opts=opts.LabelOpts(is_show=True),
            )
                .render("templates/basic_line_chart.html")
        )
Bookline()
